package org.aeon.server.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.annotation.Incomplete;
import org.aeon.entity.dto.GroupInfoDto;
import org.aeon.message.request.GroupInfoRequestMessage;
import org.aeon.message.response.GroupInfoResponseMessage;
import org.aeon.service.factory.ChatGroupServiceFactory;

/**
 * @author: MissingAeon
 * @date: 2024/2/23 11:35
 * @description:
 */
@Slf4j
@ChannelHandler.Sharable
@Incomplete
public class GroupInfoRequestHandler extends SimpleChannelInboundHandler<GroupInfoRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupInfoRequestMessage msg) throws Exception {
        final GroupInfoResponseMessage resMsg = new GroupInfoResponseMessage();
        resMsg.setResponseID(msg.getUid());

        final Long groupId = msg.getGroupId();
        final GroupInfoDto groupInfo = ChatGroupServiceFactory.getService().getChatGroupInfo(groupId);
        if (groupInfo != null) {
            resMsg.setResponse(true, "信息获取成功");
            resMsg.setMessage(groupInfo);
            ctx.writeAndFlush(resMsg);
        } else {
            resMsg.setResponse(false, "该id不存在");
            ctx.writeAndFlush(resMsg);
        }
    }
}
